{extend name='public/base' /}

{block name="content"}

<div class="layui-col-md12">
    <div class="layui-card">
        <div class="layui-card-body">
            <form action="" class="layui-form" method="get">
                <div class="layui-form-item layui-form-pane">



<!--                    <div class="layui-inline">-->
<!--                        <label class="layui-form-label" style="width: 115px!important;">缴费项类别:</label>-->
<!--                        <div class="layui-input-inline">-->
<!--                            <select name="type" >-->
<!--                                <option value="" >请选择</option>-->
<!--                                <option value="1" >保证金押金</option>-->
<!--                                <option value="2" >保证金押金</option>-->
<!--                                <option value="3" >能源费</option>-->
<!--                                <option value="4" >物业费</option>-->
<!--                                <option value="5" >其他</option>-->
<!--                            </select>-->
<!--                        </div>-->
<!--                    </div>-->
                    <div class="layui-inline">
                        <label class="layui-form-label" style="overflow: inherit;">费用项名称：</label>
                        <div class="layui-input-inline">
                            <input name="cost_name" class="layui-input" id="brand" value="" type="text"
                                   placeholder="费用项名称">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn icon-btn layui-btn-sm" data-id="table_id" lay-filter="search" lay-submit="">
                            <i class="layui-icon"></i>搜索
                        </button>
                        <button type="reset" class="layui-btn icon-btn layui-btn-normal layui-btn-sm"><i class="layui-icon layui-icon-refresh"></i>{:__('Reset')}</button>
                    </div>
                </div>
            </form>
        </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table class="layui-hide" id="table_id" lay-filter="table_id"></table>
        </div>
    </div>

</div>
{/block}

{block name="js"} <!--js处理区-->
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
       <button type="button" lay-event="add" class="layui-btn {:node('CostType/add')} layui-btn-sm">添加缴费项</button>
        <button type="button" lay-event="reload" class="layui-btn  layui-btn-sm  layui-btn-primary">刷新表格</button>
        <button type="button" lay-event="remark" class="layui-btn  layui-btn-sm  layui-btn-primary">设置开票备注</button>
    </div>
</script>
<script type="text/html" id="operationTpl">
    <a href="javascript:;" class="layui-btn layui-btn-normal layui-btn-xs {:node('CostType/add')}" data-title="编辑"
       lay-event="edit"><i class="layui-icon"></i></a>
<!--    {{# if(d.id != 1 && d.id != 2 && d.id != 3){ }}-->
<!--    <a href="javascript:;" class="layui-btn layui-btn-danger layui-btn-xs {:node('pay_type/del')}" data-title="删除"-->
<!--       lay-event="del"><i class="layui-icon "></i></a>-->
<!--    {{# } }}-->
</script>
<script>
    layui.use(['element', 'table', 'form', 'jquery', 'lucky', 'opTable'], function () {
        var element = layui.element;
        var form = layui.form;
        var table = layui.table;
        var $ = layui.jquery;
        var lucky = layui.lucky;
        var opTable = layui.opTable;
        form.render();

        var myTables = table.render({
            elem: '#table_id',
            url: "{:url('index')}",
            toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
            defaultToolbar: ['filter', 'exports', 'print'],
            even: true, //开启隔行背景
            id: 'table_id',
            page: { //支持传入 laypage 组件的所有参数（某些参数除外，如：jump/elem） - 详见文档
                layout: ['limit', 'count', 'prev', 'page', 'next', 'skip', 'last'] //自定义分页布局
                , groups: 5 //只显示 1 个连续页码
                , first: false //不显示首页
                , last: false //不显示尾页
                , limit: 20
                , limits: [10, 20, 30, 50]
            },
            // height: 'full-100',100',
            text: {
                none: '暂无相关数据'
            },
            cols: [[
                {title: 'ID', field: 'id'},
                {title: '缴费项名称', field: 'cost_name'},
                {title: '海鼎费用编号', field: 'cost_type_id'},
                {title: '收费科目编号', field: 'cost_sn'},
                {title: '税金科目编号', field: 'carry_down_sn'},
                {title: '商品名称(开票)', field: 'goods_info'},
                {title: '税率名称', field: 'tax_name'},
                {title: '税率编号', field: 'tax_sn'},
                {title: '结转科目名称', field: 'carry_down_name'},
                {title: '结转科目编号', field: 'carry_down_sn'},
                {title: '成本中心', field: 'cost_center'},
                {title: '成本中心编号', field: 'cost_center_sn'},
                // {title: '单价', field: 'cost_money'},
                {title: '是否可以开票',field: 'isinvoice',templet: function (item){
                    if(item.isinvoice==1){
                        return '可开票'
                    }else {
                        return '不可开票';
                    }
                    }},
                // {title: '创建时间', field: 'create_time',templet:function (item){
                //         return layui.util.toDateString((item.create_time) * 1000)
                //     }},
                {templet: '#operationTpl', width: 160, align: 'left', title: '操作'}
            ]],
            //  展开的列配置
            openCols: [
                {field: 'desc', title: '描述信息'}
            ],
            done: function (res) {
                layer.closeAll('loading');
            }
        });


        /**
         * 监听单行工具操作
         */
        table.on('tool(table_id)', function (obj) {
            var data = obj.data;
            var _id = parseInt(data.id);
            var layEvent = obj.event;
            if (layEvent === "edit") {
                var urls = "{:url('add')}?id=" + _id;
                lucky.CreateOpenForm("编辑", urls);

            } else if (layEvent === "del") {
                lucky.FormatData(_id, "{:url('del')}");
            }
        });


        table.on('toolbar(table_id)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data;
            if (obj.event === "add") {
                lucky.CreateOpenForm("添加 ", "{:url('add')}");
                return false;
            }else if (obj.event === "remark") {
                lucky.CreateOpenForm("设置租金发票备注 ", "{:url('remark')}");
                return false;
            }  else if (obj.event === "close") {
                opTables.closeAll();
            } else if (obj.event === "open") {
                opTables.openAll();
            } else if (obj.event === "reload") {
                lucky.CreateReload();
            } else if (obj.event === "del") {
                var num = 0;
                var id = [];
                for (var i in data) {
                    num++;
                    id.push(data[i].id);
                }
                if (num < 1) {
                    layer.msg("请选择一项", {time: 1500});
                    return false;
                }
                lucky.FormatData(id, "{:url('del')}");
                return false;
            }
        });

        /**
         * 关键词搜索树
         */
        form.on('submit(search)', function (obj) {
            lucky.CreateSearch(obj.field);
            return false;
        });
    });

</script>

{/block}
